package server.protocol.processor;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import server.command.receive.Command;
import server.config.processor.ConfigProcessor;
import server.exception.processor.ReceiveException;

public class ReceiveProtocolProcessor {
	
	public Command process(String rec) throws ReceiveException, UnsupportedEncodingException{
		
		String resource=rec.substring(rec.indexOf('/'),rec.lastIndexOf('/')-5);
		resource=URLDecoder.decode(resource, "UTF-8");
		String url;
		System.out.println("rec : " + rec);
		System.out.println("resource : " + resource);
		Command command;
		if(resource.contains("?")){
			url = resource.split("\\?")[0];
			command = ConfigProcessor.getHp().get(url);
			if(resource.split("\\?").length > 0){
				command.setCommandValue(resource.split("\\?")[1]);
			}
		}else {
			url = resource;
			command = ConfigProcessor.getHp().get(url);
		}
		return command;
	}
}
